import { Course } from "src/school/course/entities/course.entity";
import { Teacher } from "src/school/teacher/entities/teacher.entity";
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  JoinTable,
  ManyToMany,
  OneToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from "typeorm";

@Entity()
export class Class {
  //自增列
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ comment: "班级" })
  gradeAndClass: string;

  @Column({ comment: "班主任" })
  classTeacher: string;

  @Column({ comment: "班主任id" })
  classTeacherId: number;

  @Column({ comment: "文理科 0-未分科 1-文科 2-理科", type: "enum", enum: [0, 1, 2] })
  subject: 0 | 1 | 2;

  @Column({ comment: "创建人", default: null })
  createBy: string;

  @Column({ comment: "创建人id", default: null })
  createById: number;

  @Column({ comment: "更新人", default: null })
  updateBy: string;

  @Column({ comment: "更新人id", default: null })
  updateById: number;

  @CreateDateColumn({ comment: "班级创建时间" })
  createDate: Date;

  @UpdateDateColumn({ comment: "班级更新时间" })
  updateDate: Date;

  @OneToOne(() => Course, { eager: true, cascade: true })
  @JoinColumn()
  course: Course;

  @ManyToMany(() => Teacher, teacher => teacher.classes, { cascade: true })
  @JoinTable({
    name: "class_teacher", // 关联表的名称
    joinColumns: [{ name: "classId" }],
    inverseJoinColumns: [{ name: "teacherId" }],
  })
  teachers: Teacher[];
}
